package com.xinhe.web.controller;

import com.querydsl.core.QueryResults;
import com.xinhe.web.annotation.WebUsed;
import com.xinhe.web.common.Result;
import com.xinhe.web.entity.ServiceCenter;
import com.xinhe.web.request.ServiceCenterQuery;
import com.xinhe.web.service.ServiceCenterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "服务中心", tags = {"服务中心"})
@RestController
@RequestMapping(value = {"/serviceCenter"}, produces = {"application/json;charset=UTF-8"})

public class ServiceCenterController {
    @Autowired
    private ServiceCenterService serviceCenterService;

    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "分页查询服务中心，即综合统计")
    @RequestMapping({"/pageServiceCenter"})
    public QueryResults<ServiceCenter> pageServiceCenter(ServiceCenterQuery query) {
        return serviceCenterService.pageServiceCenter(query);
    }

    @ApiOperation(httpMethod = "GET", value = "获取不等于当前id的服务中心")
    @RequestMapping({"/findByNotServiceCenter"})
    public Result findByNotServiceCenter(Long serviceCenterId) {
        return serviceCenterService.findByNotServiceCenter(serviceCenterId);
    }

    @WebUsed
    @ApiOperation(httpMethod = "POST", value = "保存服务中心")
    @RequestMapping({"/saveServiceCenter"})
    public Result saveServiceCenter(String name,String address,String longitude,String latitude) {
        return serviceCenterService.saveModel(name,address,longitude,latitude);
    }
    @WebUsed
    @ApiOperation(httpMethod = "POST", value = "修改服务中心")
    @RequestMapping({"/updateServiceCenter"})
    public Result updateServiceCenter(Long id,String name,String address,String longitude,String latitude) {
        return serviceCenterService.updateModel(id,name,address,longitude,latitude);
    }

    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "删除服务中心")
    @RequestMapping({"/deleteServiceCenter"})
    public Result deleteServiceCenter(Long id) {
        return serviceCenterService.deleteServiceCenter(id);
    }

    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "服务中心详情")
    @RequestMapping({"/detailServiceCenter"})
    public Result detailServiceCenter(Long id) {
        Result result = serviceCenterService.findById(id);
        return result;
    }

    @WebUsed
    @ApiOperation("合并服务中心")
    @PostMapping({"/updateMergeServiceCenter/{serviceCenterId}"})
    public Result updateMergeServiceCenter(@PathVariable("serviceCenterId") Long serviceCenterId, @RequestBody List<Long> list) {
        return serviceCenterService.updateMergeServiceCenter(serviceCenterId,list);
    }

}
